﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.Bll;
using Acms.AcmsControls;


public partial class Templates_VideoHolder_Default : Acms.AcmsControls.TemplatePage
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        dsList.SelectData += new EventHandler<Acms.DataControls.SelectEventArgs<Acms.Bll.Post>>(dsList_SelectData);
        dlFeed.ItemDataBound += new EventHandler<Acms.WebControls.ItemDataBoundEventArgs>(dlFeed_ItemDataBound);
        dsSibling.SelectData += new EventHandler<Acms.DataControls.SelectEventArgs<Acms.Bll.Post>>(dsSibling_SelectData);
        dlNavSiblings.ItemDataBound += new EventHandler<Acms.WebControls.ItemDataBoundEventArgs>(dlNavSiblings_ItemDataBound);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (AcmsContext.CurrentPost != null)
            {
                //FLASH STUFF
                string url = null;
                if (AcmsContext.CurrentPost.Path == "~")
                {
                    url = "~/default.aspx";
                }
                else
                {
                    url = string.Concat(AcmsContext.CurrentPost.Path, ".aspx");
                }
                //VideoCarousel.Variables.Add("SettingsFilePath", AcmsContext.FullyQualifiedUrl(url, "FlashXml", this));

                //VideoCarousel.Variables.Add("SiteRoot", string.Concat("http://", AcmsContext.SiteRoot));

                //VideoCarousel.Variables.Add("trackName", url);
            }
             
            DataBind();
        }

    }

    protected string GetFlashXML()
    {
        string url = null;
        url = string.Concat(AcmsContext.CurrentPost.Path, ".aspx");
        return AcmsContext.FullyQualifiedUrl(url, "FlashXml", this);
        //return "http://" + HttpContext.Current.Request.Url.Host + ResolveUrl("~/Flash/VideoCarousel.swf");
    }
    protected string GetFlash()
    {
        return "http://" + HttpContext.Current.Request.Url.Host + ResolveUrl("~/Flash/VideoCarousel.swf");
    }

    



    void dsList_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.Post> e)
    {
        e.SetData(AcmsContext.CurrentPost.Children.OrderBy(x => x.Sequence).ToList());
    }
    void dlFeed_ItemDataBound(object sender, Acms.WebControls.ItemDataBoundEventArgs e)
    {
        
                //lnk.Attributes.Add("rel", "Next");

                //var showLnkMov = post.FindPostControl("ShowLnkMov");
                //var showLnkMovProp = showLnkMov.GetProperties<Acms.AcmsControls.TrueFalseContentControlProperties>();
                ////var showlnkMovValue = showLnkMovProp.Value;
                
                //if(showLnkMovProp != null && showLnkMovProp.Value)
                //{
                //    lnkMov.Visible = true;
                //}else{
                //    lnkMov.Visible = false;
                //}
                //if (showlnkMovValue != null)
                //{
                //     var showLnkMovValue = showLnkMov.Value;
                //  //  lnkMov.Visible = showLnkMovValue;
                //}
     
     
    }
    void dsSibling_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.Post> e)
    {
        e.SetData(AcmsContext.CurrentPost.Parent.Children.OrderBy(x => x.Sequence).ToList());
    }
    void dlNavSiblings_ItemDataBound(object sender, Acms.WebControls.ItemDataBoundEventArgs e)
    {
        var post = e.DataItem as Post;
        if (post != null)
        {
            var lnk = e.Item.FindControl("lnkNav") as HyperLink;

            if (lnk != null)
            {
                lnk.Text = post.DisplayName;
                lnk.NavigateUrl = post.Url;
            }
        }
    }
    //protected string GetFlash()
    //{
    //    return "http://" + HttpContext.Current.Request.Url.Host + ResolveUrl("~/Flash/VideoCarousel.swf");
    //}
    
    //protected string GetImgSrc()
    //{
    //    var heroImage = AcmsContext.CurrentPost.FindPostControl("HeroImage");
    //    var host = HttpContext.Current.Request.Url.Host;
    //    if (heroImage != null)
    //    {
    //        var heroImageProperties = heroImage.GetProperties<Acms.AcmsControls.ImageContentControlProperties>();
    //        if (heroImageProperties != null)
    //        {
    //            return "http://"+host+ResolveUrl(Acms.AcmsControls.RenderFile.GetUrl(heroImageProperties.ResourceId, null, null, this));
    //        }
    //    }
    //    return null;
    //}

   
}
